﻿using System;
using System.Collections.Generic;
using System.Linq;
using PocketBook.Model;
using PocketBook.Properties;

namespace PocketBook.ViewModels.Designs
{
    [DesignResources(typeof(Resources))]
    public class WeekPage : Design
    {
        public WeekPage()
        {
            StartOfWeek = StartOfWeekFor(DateTime.Today);
        }

        public DateTime StartOfWeek
        {
            get;
            set;
        }

        public IEnumerable<DateTime> DaysOfWeek
        {
            get { return Enumerable.Range(0, 5).Select(n => StartOfWeek + TimeSpan.FromDays(n)); }
        }

        public IEnumerable<DateTime> DaysOfWeekend
        {
            get { return Enumerable.Range(5, 2).Select(n => StartOfWeek + TimeSpan.FromDays(n)); }
        }

        public override object Clone()
        {
            var design = (WeekPage)base.Clone();
            design.StartOfWeek = StartOfWeek;

            return design;
        }

        public static DateTime StartOfWeekFor(DateTime time)
        {
            var cultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture;
            return time.AddDays(-(time.DayOfWeek - cultureInfo.DateTimeFormat.FirstDayOfWeek));
        }
    }
}